#include <iostream>
#include<algorithm>
using namespace std;

typedef long long ll;
const int N = 2e5 + 10;
ll n, m, l, r;
ll a[N], b[N];

bool check(ll x){
  ll v = m;
  for(int i = 1; i <= n; i++){
    if(a[i] > x) continue;
    if(a[i] + b[i] < x) return false;
    if(a[i] + b[i] >= x && v >= x - a[i]){
    	v -= (x - a[i]);
	}
	else {
		return false;
	}
}
	return true;
}

int main()
{
  cin >> n >> m;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }
  for(int i = 1; i <= n; i++) cin >> b[i];
  l = 1,r = 4e5;
  while(l < r){
    ll mid = (l + r + 1) / 2;
    if(check(mid)) l = mid;
    else r = mid - 1;
  }
  cout << l << endl;
  return 0;
}
